package com.cl.cloud.binlog.config;

import com.cl.cloud.binlog.content.BinLogApplicationContext;
import com.cl.cloud.binlog.factory.BinaryLogClientFactory;
import com.cl.cloud.binlog.factory.DefaultBinaryLogClientFactory;
import com.cl.cloud.binlog.handler.*;
import com.cl.cloud.binlog.properties.BinLogProperty;
import com.cl.cloud.binlog.runner.ContextInitRunner;
import com.cl.core.redis.cache.RedisJsonOpt;
import com.cl.core.redis.lock.RedisLockClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description:
 * @author: liuzijian
 * @time: 2022-07-08 16:01
 */
@Configuration
public class BinlogConfiguration {


    @Bean
    public ContextInitRunner contextInitRunner(BinLogProperty property, @Qualifier("binLogApplicationContext") BinLogApplicationContext context) {
        return new ContextInitRunner(property, context);
    }

    @Bean
    public BinLogApplicationContext binLogApplicationContext(BinLogProperty property) {
        return new BinLogApplicationContext();
    }

    @Bean
    public DistributedClientHandler redisDistributedClientHandler(BinLogApplicationContext context, RedisLockClient redissonClient) {
        return new RedisDistributedClientHandler(context, redissonClient);
    }

    @Bean
    public PositionHandler redisPositionHandler(RedisJsonOpt redisJsonOpt) {
        return new RedisPositionHandler(redisJsonOpt);
    }

    @Bean
    public BinaryLogClientFactory clientFactory(BinLogApplicationContext context) {
        return new DefaultBinaryLogClientFactory(context);
    }
}
